var React = require('react');
var ReactDOM = require('react-dom');
var Cookie  = require("./common-component/cookie/cookie");
var _ = require("underscore");

var { Router, Route, hashHistory,Link,history,IndexRoute} = require('react-router');


var Index = require("./app/index/index.jsx");
//内部功能组件引入  按需加载
var Login = function(nextState, cb){require.ensure([], (require) => {cb(null, require('./app/login/login.jsx'))}, "Login")};
var Error = function(nextState, cb){require.ensure([], (require) => {cb(null, require('./common-component/error/error.jsx'))}, "Error")};
//var Index = function(nextState, cb){require.ensure([], (require) => {cb(null, require('./app/index/index.jsx'))}, "Index")};



//布局组件引入
var Nav = require('./layout/nav');
var ToolBar = require('./layout/tool-bar');
var Header = require('./layout/header');
var Footer = require('./layout/footer');

//样式文件引入
require('./asset/style/reset.scss');
require('./asset/style/common.scss');

/*moke菜单json文件加载*/
var menuJson = require("./moke_json/menu.json");

var Api = require("./api/api");

var Util = require("./common-component/util/util.js");



var App = React.createClass({
  getInitialState() {
    return{
      menuData:menuJson
    }
  },

  render() {
     var {menuData} = this.state;
      return (
          <div className="app-layout clearfix">
            <ToolBar isReg={false}/>
            <Header data={menuData}  isReg={false}/>
            <div className="container clearfix">
              <Nav data={menuData}/>
              <div className="content">
                <div className="workspace-layout" >
                  { this.props.children }
                </div>
              </div>
            </div>
            <Footer />
          </div>);
  }
});
/*登录后内部组件路由，业务组件模块都在这里配置*/
var Routers = React.createClass({
  render:function() {
    //var cookie = new Cookie();
    //var isLogin = !!cookie.getCookie("token");
    //if(!isLogin){
    //    hashHistory.push('/login');
    //}else{
    //    hashHistory.push('/product-main');
    //}
    return (
        <Router history={hashHistory}>
          <Route path="/" component={App}>
            <IndexRoute component={Index}/>
            /*用户中心路由*/
            <Route path="/login(/:aimPath)" getComponent={Login}/>
            <Route path="/error(/:msg)" getComponent={Error}/>
            <Route path="/index" component={Index}/>
          </Route>
        </Router>
    )
  }
});


ReactDOM.render(<Routers />, document.getElementById('app-container'));